package com.yami.shop.app.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.google.zxing.common.StringUtils;
import com.yami.shop.app.utils.HttpResult;
import com.yami.shop.bean.cashregisterapp.AppProductPool;
import com.yami.shop.bean.param.ProductParam;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.security.util.SecurityUtils;
import com.yami.shop.service.AppProductPoolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Controller
@RequestMapping("/app/appProductPool")
public class AppProductPoolController {

    @Autowired
    private AppProductPoolService appProductPoolService;

    /**
     * 查询商品池商品信息
     * */
    @PostMapping("/getProductPool")
    @ResponseBody
    public HttpResult getProducts(ProductParam product, PageParam<AppProductPool> page){
        IPage<AppProductPool> products = appProductPoolService.page(page,
                new LambdaQueryWrapper<AppProductPool>()
                        .like(StrUtil.isNotBlank(product.getProdName()), AppProductPool::getProdName, product.getProdName())
                        .eq(product.getStatus() != null, AppProductPool::getStatus, product.getStatus())
                        .orderByDesc(AppProductPool::getPutawayTime));
        return HttpResult.success(products);
    }

    /**
     * 查询商品详情接口
     * */
    @PostMapping("getProductById")
    @ResponseBody
    public HttpResult getProductById(Long appProdPoolId){
        AppProductPool appProductPool = appProductPoolService.getById(appProdPoolId);
        return HttpResult.success(appProductPool);
    }

    /**
     * 添加商品
     * */
/*    @PostMapping("/addProduct")
    @ResponseBody
    public HttpResult addProduct(ProductParam productParam){
        Product product = productService.getOne(
                new LambdaQueryWrapper<Product>()
                .eq(Product::getShopId,SecurityUtils.getSysUser().getShopId())
                .eq(Product::getBarCode,productParam.getBarCode())
        );
        if(product!=null){
            return HttpResult.failure("商品码已存在，请重新生成");
        }
        Long shopId=SecurityUtils.getSysUser().getShopId();
        productService.insertProduct(productParam,shopId);
        return HttpResult.success();
    }*/

}
